package com.example.rightmost.controller.admin;

import com.example.rightmost.entity.Comment;
import com.example.rightmost.service.CommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author:javayhch
 * @date:2024/8/22
 * @description:
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    public CommentService commentService;

    @RequestMapping("/getCommentList")
    public PageInfo getCommentList(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "5") int size,
                                 @RequestParam String text
    ){
        PageHelper.startPage(page, size);
        List<Comment> list = commentService.getCommentList(text);
        PageInfo<Comment> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @RequestMapping("/getCommentArea")
    public PageInfo getCommentArea(@RequestParam(defaultValue = "1") int page,
                                      @RequestParam(defaultValue = "5") int size,
                                      @RequestBody Comment comment
    ){
        PageHelper.startPage(page, size);
        List<Comment> list = commentService.getCommentArea(comment);
        PageInfo<Comment> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @RequestMapping("/getCommentSonList")
    public PageInfo getCommentSonList(@RequestParam(defaultValue = "1") int page,
                                      @RequestParam(defaultValue = "5") int size,
                                      @RequestBody Comment comment
    ){
        PageHelper.startPage(page, size);
        List<Comment> list = commentService.getCommentSonList(comment);
        PageInfo<Comment> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
